<?php

    defined('BASEPATH') OR exit('No direct script access allowed');

    Class Template {

        var $template_data = array();
        var $template_view = "template";

        function set($name, $value) {
            $this->template_data[$name] = $value;
        }

        function set_view($name) {
            $this->template_view = $name;
        }

        function load($view = '', $view_data = array(), $return = FALSE) {
            $this->CI = & get_instance();

            /* Unset lang wich is set in myHook, create clean URL for change language */
            if (isset($_GET['lang']))
                unset($_GET['lang']);

            $view_data['template_lang'] = "";
            if (!empty($_GET))
                $view_data['template_lang'] = '?' . http_build_query($_GET);

            /* Create clean URL for currency change */
            $view_data['template_currency'] = "";
            $view_data['currency_prefix'] = "?";
            $temp_GET = $_GET;
            if (isset($temp_GET['currency']))
                unset($temp_GET['currency']);

            if (!empty($temp_GET)):
                $view_data['template_currency'] = "?" . http_build_query($temp_GET);
                $view_data['currency_prefix'] = '&';
            endif;

            /* Create logo URL if currency change */
            if (function_exists('lang_url'))
                $view_data['template_logo_URL'] = lang_url();
            if (isset($_GET['currency']))
                $view_data['template_logo_URL'].="?currency=" . $_GET['currency'];


            $this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
            return $this->CI->load->view('' . $this->template_view, $this->template_data, $return);
        }

    }

?>
